package com.sdb.clinic.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sdb.common.annotation.Log;
import com.sdb.common.core.controller.BaseController;
import com.sdb.common.core.domain.AjaxResult;
import com.sdb.common.enums.BusinessType;
import com.sdb.clinic.domain.TdRegister;
import com.sdb.clinic.service.ITdRegisterService;
import com.sdb.common.utils.poi.ExcelUtil;
import com.sdb.common.core.page.TableDataInfo;

/**
 * 挂号Controller
 * 
 * @author yyh
 * @date 2025-01-08
 */
@RestController
@RequestMapping("/clinic/register")
public class TdRegisterController extends BaseController
{
    @Autowired
    private ITdRegisterService tdRegisterService;

    /**
     * 查询挂号列表
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @GetMapping("/list")
    public TableDataInfo list(TdRegister tdRegister)
    {
        startPage();
        List<TdRegister> list = tdRegisterService.selectTdRegisterList(tdRegister);
        return getDataTable(list);
    }

    /**
     * 获取患者个人挂号列表
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @GetMapping("/listUserRegister")
    public TableDataInfo listPerson(TdRegister tdRegister)
    {
        startPage();
        List<TdRegister> list = tdRegisterService.listUserRegister(tdRegister);
        return getDataTable(list);
    }


    /**
     * 获取当日挂号列表
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @GetMapping("/listToday")
    public TableDataInfo index(TdRegister tdRegister)
    {
        List<TdRegister> list = tdRegisterService.selectTodayTdRegisterList(tdRegister);
        return getDataTable(list);
    }

    /**
     * 历史挂号数据
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @GetMapping("/listHistory")
    public TableDataInfo history(TdRegister tdRegister)
    {
        List<TdRegister> list = tdRegisterService.selectHistoryTdRegisterList(tdRegister);
        return getDataTable(list);
    }

    /**
     * 查询待发药患者
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @GetMapping("/listSend")
    public TableDataInfo wait(TdRegister tdRegister)
    {
        List<TdRegister> list = tdRegisterService.selectWaitTdRegisterList(tdRegister);
        return getDataTable(list);
    }

    /**
     * 导出挂号列表
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @Log(title = "挂号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TdRegister tdRegister)
    {
        List<TdRegister> list = tdRegisterService.selectTdRegisterList(tdRegister);
        ExcelUtil<TdRegister> util = new ExcelUtil<TdRegister>(TdRegister.class);
        util.exportExcel(response, list, "挂号数据");
    }

    /**
     * 获取挂号详细信息
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @GetMapping(value = "/{registerId}")
    public AjaxResult getInfo(@PathVariable("registerId") Long registerId)
    {
        return success(tdRegisterService.selectTdRegisterByRegisterId(registerId));
    }

    /**
     * 新增挂号
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @Log(title = "挂号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TdRegister tdRegister)
    {
        return toAjax(tdRegisterService.insertTdRegister(tdRegister));
    }

    /**
     * 新增个人挂号
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @Log(title = "个人挂号", businessType = BusinessType.INSERT)
    @PostMapping("/personregister")
    public AjaxResult addPerson(@RequestBody TdRegister tdRegister)
    {
        return toAjax(tdRegisterService.insertPersonTdRegister(tdRegister));
    }

    /**
     * 新增预约挂号
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @Log(title = "预约挂号", businessType = BusinessType.INSERT)
    @PostMapping("/bookregister")
    public AjaxResult addBookRegister(@RequestBody TdRegister tdRegister)
    {
        return toAjax(tdRegisterService.insertBookTdRegister(tdRegister));
    }

    /**
     * 修改挂号
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @Log(title = "挂号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TdRegister tdRegister)
    {
        return toAjax(tdRegisterService.updateTdRegister(tdRegister));
    }

    /**
     * 删除挂号
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @Log(title = "挂号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{registerIds}")
    public AjaxResult remove(@PathVariable Long[] registerIds)
    {
        return toAjax(tdRegisterService.deleteTdRegisterByRegisterIds(registerIds));
    }

    /**
     * 修改挂号状态为已就诊
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @Log(title = "挂号", businessType = BusinessType.UPDATE)
    @PutMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody String clinicId)
    {
        return toAjax(tdRegisterService.updateStatus(clinicId));
    }
}
